<script>
    $(document).ready(function() {
        $("#cardBarcode").change(function() {
            $("#form_new_reader").submit();
        });
        $("#bookBarcode").change(function() {
            $("#form_new_reader").submit();
        });
    });
</script>
<!--<div id="form-top">-->
<div class="onecolumn">
    <div class="header">
        <span style="color: red; text-align: center; font-weight: bold;">Bạn đọc trả tài liệu</span>
    </div>
    <br class="clear"/>
    <div id="form-top">
        <?php
        $form = $this->form;
        $form->setAttribute('action', $this->url('return-document/default', array('action' => 'index',)));
        $form->prepare();
        echo $this->form()->openTag($form);
        ?>
        <fieldset>
            <legend>Thông tin bạn đọc</legend>
            <?php if (isset($profilePhoto) && $profilePhoto != null) : ?>
                <img src="<?php echo $this->basePath() . $profilePhoto; ?>" >   
            <?php endif; ?>
            <p>
                <?php
                echo $this->formLabel($form->get('fullName'));
                echo $this->formInput($form->get('fullName'));
                ?>
            </p>
            <p>
                <?php
                echo $this->formLabel($form->get('cardBarcode'));
                echo $this->formInput($form->get('cardBarcode'));
                ?>
            </p>
            <p>
                <?php
                echo $this->formLabel($form->get('residentAddress'));
                echo $this->formInput($form->get('residentAddress'));
                ?>
            </p>
            <p>
                <?php
                echo $this->formLabel($form->get('accountStatus'));
                echo $this->formInput($form->get('accountStatus'));
                ?>
            </p>
            <p>
                <?php
                echo $this->formLabel($form->get('classID'));
                echo $this->formInput($form->get('classID'));
                ?>
            </p>
            <p>
                <?php
                echo $this->formLabel($form->get('isActive'));
                echo $this->formInput($form->get('isActive'));
                ?>
            </p>
            <div class="viewMessae" style="text-align: center">
                <?php
                if (isset($myMessage)) {
                    foreach ($myMessage as $key => $message) {
                        if ($message == "notFoundReader")
                            echo '<span style="color:red;font-weight:bold;float:right;margin-right:400px;margin-top:30px;">Không tìm thấy bạn đọc cho mã thẻ này</span><br/>';
                        if ($message == "cardBarcode")
                            echo '<span style="color:red;font-weight:bold;float:right;margin-right:400px;margin-top:60px;">Giá trị nhập vào không đúng</span><br/>';
                    }
                }
                ?>
            </div>
        </fieldset>
        <br class="clear"/>
        <fieldset>
            <legend>Chi tiết tài liệu </legend>
            <p>
                <?php
                echo $this->formLabel($form->get('statusDocument'));
                echo $this->formInput($form->get('statusDocument'));
                ?>
            </p>
            <p>
                <?php
                echo $this->formLabel($form->get('bookBarcode'));
                echo $this->formInput($form->get('bookBarcode'));
                ?>
            </p>
            <p>
                <?php
                echo $this->formLabel($form->get('dateReturn'));
                echo $this->formInput($form->get('dateReturn'));
                ?>
            </p>
            <p>
                <?php
                echo $this->formLabel($form->get('typeDocument'));
                echo $this->formInput($form->get('typeDocument'));
                ?>
            </p>         

            <p>
                <?php
                echo $this->formLabel($form->get('locationDocument'));
                echo $this->formInput($form->get('locationDocument'));
                ?>
            </p>
            <p>
                <?php
                echo $this->formRow($form->get('descriptionDocument'));
                ?>
            </p>
            <br class="clear"/>
            <div class="viewMessae" style="text-align: center">
                <?php
                if (isset($myMessage)) {
                    foreach ($myMessage as $key => $message) {
                        if ($message == "notExistInfo")
                            echo '<span style="color:red;font-weight:bold;float:right;margin-right:400px;margin-top:60px;">Bạn chưa điền đủ thông tin</span><br/>';
                        if ($message == "notFoundBook")
                            echo '<span style="color:red;font-weight:bold;float:right;margin-right:400px;margin-top:60px;">Không tìm thấy thông tin sách cho mã này</span><br/>';
                        if ($message == "returnOK")
                            echo '<span style="color:red;font-weight:bold;float:right;margin-right:400px;margin-top:60px;">Trã sách thành công</span><br/>';
                        if ($message == "returnError")
                            echo '<span style="color:red;font-weight:bold;float:right;margin-right:400px;margin-top:60px;">Xảy ra lỗi - Có thể tài liệu chưa được mượn hoặc không đúng với người trả</span><br/>';
                    }
                }
                ?>
            </div>
            <div id="button-return">
                <?php
                echo $this->formInput($form->get('returnDocument'));
                ?>
                <input type="reset" name="reset" value="Reset">
            </div>
        </fieldset>
        <!-- Thông tin tài liệu -->
        <?php echo $this->form()->closeTag($form); ?>
    </div>
</div>
<!-- Chi tiết về tài liệu đang mượn -->
<!-- Begin one column window -->
<?php if (isset($paginator) && $paginator != null) : ?>
    <div class="onecolumn">
        <div class="header">
            <span style="color: red;">Danh sách tài liệu đang mượn</span>
        </div>
        <br class="clear"/>
        <div class="content">
            <form id="form_data" name="form_data" action="" method="post">
                <table class="data" width="100%" cellpadding="0" cellspacing="0">
                    <thead>
                        <tr>
                            <th>
                                <input type="checkbox" id="check_all" name="check_all"/>
                            </th>
                            <th style="width:10%">Mã tài liệu</th>
                            <th style="width:30%">Mô tả</th>
                            <th style="width:10%">Ngày mượn</th>
                            <th style="width:10%">Ngày trả</th>
                            <th style="width:10%">Gia hạn</th>
                            <th style="width:10%">Quá hạn(ngày)</th>
                            <th style="width:10%">Tình trạng</th>
                            <th style="width:10%">Thao tác</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php foreach ($paginator as $row) : ?>
                            <tr>
                                <td>
                                    <input type="checkbox"/>
                                </td>
                                <td><?php echo $this->escapeHtml($row->bookBarcode) . '-' . $this->escapeHtml($row->serial); ?></td>
                                <td>
                                    <?php
                                    echo $this->escapeHtml($row->title . ' / ' . $allAuthor[$row->bookBarcode] . ' / Số trang: ' . $row->numberOfPages . ' / ' . $row->publisher . ' / Giá: ' . $row->price);
                                    ?>
                                </td>
                                <td>
                                    <?php
                                    $dateBorrow = explode('-', $row->dateBorrow);
                                    echo $this->escapeHtml($dateBorrow[2] . '/' . $dateBorrow[1] . '/' . $dateBorrow[0]);
                                    ?>
                                </td>
                                <td>
                                    <?php
                                    $dateReturn = explode('-', $row->dateReturn);
                                    echo $this->escapeHtml($dateReturn[2] . '/' . $dateReturn[1] . '/' . $dateReturn[0]);
                                    ?>
                                </td>
                                <td>
                                    <?php
                                    echo $this->escapeHtml($row->addTime);
                                    ?>
                                </td>
                                <td>
                                    <?php
                                     $arraydateCurrent = explode('-',date('Y-m-d'));
                                     $arrayDateReturn = explode('-',$row->dateReturn);
                                     $dateCurrent = new DateTime(date('Y-m-d'));
                                     $dateReturn = new DateTime($row->dateReturn);
                                     $year = $arraydateCurrent[0] - $arrayDateReturn[0];
                                     $month = $arraydateCurrent[1] - $arrayDateReturn[1];
                                     $interval = $dateCurrent->diff($dateReturn);
                                     if($year == 0 && $month > 0) {
                                         echo $this->escapeHtml($interval->y.' năm '.$interval->m.' th '.$interval->d.' ng');
                                     } else  if($year > 0){
                                         echo $this->escapeHtml($interval->y.' năm '.$interval->m.' th '.$interval->d.' ng');
                                     } else {
                                         echo $this->escapeHtml('0');
                                     }
                                    ?>
                                </td>
                                <td>
                                    <?php
                                    if ($row->bookStatus == 1) {
                                        echo $this->escapeHtml("Đang mượn");
                                    } else {
                                        echo $this->escapeHtml("Đã trả");
                                    }
                                    ?>
                                </td>
                                <td>
                                    <a href="<?php echo $this->url('return-document/default',array('action' => 'updateTimeBorrow','id' => $row->bookBarcode.'-'.$row->serial))?>"><img src="<?php echo $this->basePath() . '/img/icon_edit.png' ?>" alt="edit" class="help" title="Gia hạn"/></a>
                                </td>

                            </tr>
                        <?php endforeach; ?>
                    </tbody>
                </table>
                <?php
                // add at the end of the file after the table
                echo $this->paginationControl(
                        // the paginator object
                        $this->paginator,
                        // the scrolling style; see http://zf2.readthedocs.org/en/release-2.1.4/modules/zend.paginator.usage.html#rendering-pages-with-view-scripts
                        'sliding',
                        // the partial to use to render the control
                        array('partial/paginator.phtml', 'Admin'),
                        // the route to link to when a user clicks a control link
                        array(
                    'route' => 'return-docunent',
                        )
                );
                ?>
            </form>
        </div>
    </div>
<?php endif; ?>
<!-- End one column window -->